package com.deyuanyun.pic.pipe.controller;

import com.deyuanyun.pic.common.dto.PageJsonBean;
import com.deyuanyun.pic.common.util.ajax.AjaxSupport;
import com.deyuanyun.pic.pipe.controller.dto.ValveRoomQuery;
import com.deyuanyun.pic.pipe.controller.vo.ValveRoomVO;
import com.deyuanyun.pic.pipe.enumeration.PipeExportEnum;
import com.deyuanyun.pic.pipe.service.PipeMgrService;
import com.deyuanyun.pic.settings.util.DownExcelUtil;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;

import java.io.IOException;
import java.util.List;

/**
 * “场站阀室”控制类
 *
 * 功能说明
 *
 * @author    scalpel.Wang
 * @version   2015年11月19日上午9:03:22
 * @see         // 引用的类
 * Method List: 方法列表
 *
 */
@Controller
@RequestMapping("/pipe/valveRoom")
public class ValveRoomController extends PipeBaseController {

	@Resource
	private PipeMgrService pipeMgrService;

	/**
	 * 跳转到 场站阀室 主页面
	 *
	 * @return
	 */
	@RequestMapping("/toValveRoom.html")
	public ModelAndView toValveRoom(){
		ModelAndView mav=new ModelAndView();
		mav.setViewName("/basedata/gis/valveRoom");
		return mav;
	}

	/**
	 * 根据条件分页查询 场站阀室 数组对象
	 *
	 * @param valveRoomQuery
     */
	@RequestMapping("/query.json")
	@ResponseBody
	public void query(ValveRoomQuery valveRoomQuery) {
		PageJsonBean jsonBean = new PageJsonBean();
		jsonBean.setList(this.queryVO(valveRoomQuery));
		AjaxSupport.sendSuccessText("success", jsonBean);
	}


    /**
     * 根据条件分页查询 场站阀室 数组对象
     *
     * @param valveRoomQuery
     */
    @RequestMapping("/queryValveRoomById.json")
    @ResponseBody
    public void queryValveRoomById(ValveRoomQuery valveRoomQuery,ModelMap model) {
        
        List list = this.queryVO(valveRoomQuery);
        if(list != null && !list.isEmpty()){
            model.addAttribute("valveRoom", list.get(0));
        }
        AjaxSupport.sendSuccessText("success", model);
    }
	
	/**
	 * 根据条件导出 场站阀室
	 *
	 * @param valveRoomQuery
	 * @throws IOException
     */
	@RequestMapping("/export.json")
	@ResponseBody
	public void export(ValveRoomQuery valveRoomQuery) throws IOException {
		List list = this.queryVO(valveRoomQuery);
		PipeExportEnum exportEnum = PipeExportEnum.ValveRoom;
		String[] columnKeys = {"name", "customNumber", "type", "locationDescription", "isPiggingDeviceind",
				"isPowerind", "isEmptyingDevice", "recorder", "recordTime", "remark"};
		DownExcelUtil.export(exportEnum.getFileName(), pipePath+exportEnum.getTempPath(), exportEnum.getBeginRow(), list, columnKeys);
	}

	private List queryVO(ValveRoomQuery valveRoomQuery) {
		return new ValveRoomVO().fromDomainList(pipeMgrService.queryValveRoom(valveRoomQuery));
	}
}
